import 'package:flutter/material.dart';
import 'package:qgchat/common/class/eventBus/index.dart';
import 'package:qgchat/common/class/overlay/index.dart';
import 'package:qgchat/common/global/global.dart';

class NewManDialog {
  static final NewManDialog _instance = new NewManDialog._internal();
  factory NewManDialog() => _instance;
  NewManDialog._internal();

  OverlayEntry _overlayEntry;

  show() {
    _overlayEntry?.remove();
    _overlayEntry = OverlayEntry(
      builder: (context) {
        return Positioned.fill(
          child: Material(
            color: Colors.black.withOpacity(.5),
            child: Stack(
              children: <Widget>[
                GestureDetector(
                  onTap: () {
                    _overlayEntry.remove();
                  },
                ),
                Center(
                  child: SizedBox(
                    width: px(592),
                    height: px(539),
                    child: Stack(
                      alignment: Alignment.center,
                      children: <Widget>[
                        Image.asset(
                          'assets/images/new_man.png',
                          fit: BoxFit.contain,
                        ),
                        Positioned(
                          bottom: px(28),
                          child: GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              _overlayEntry.remove();
                              bus.emit("homeTabbarIndex", 2);
                            },
                            child: Container(
                              width: px(395),
                              height: px(85),
                            ),
                          ),
                        ),
                        Positioned(
                          top: px(5),
                          right: px(30),
                          child: GestureDetector(
                            onTap: () {
                              _overlayEntry.remove();
                            },
                            child: Image.asset(
                              'assets/images/icon/dialog_close.png',
                              width: px(42),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );

    appOverlayState.insert(_overlayEntry);
  }
}
